#include "stdafx.h"
#include "SphereComponent.h"

SphereComponent::SphereComponent( Ogre::Vector3 position, float radius, float mass = 1, bool movable = true ) {
	hkVector4 pos = hkVector4(position.x,position.y,position.z);

	// Create box shape using given dimensions
	hkReal m_fhkConvexShapeRadius  = 0.05f;
	hkpShape* movingBodyShape = new hkpSphereShape( radius );

	// Compute the inertia tensor from the shape
	hkpMassProperties m_massProperties;
	
	hkpInertiaTensorComputer::computeShapeVolumeMassProperties( movingBodyShape, mass, m_massProperties );

	// Create rigid body information structure 
	hkpRigidBodyCinfo m_rigidBodyInfo;
	
	// Assign the rigid body properties
	m_rigidBodyInfo.m_position = pos;
	m_rigidBodyInfo.m_mass = m_massProperties.m_mass;
	m_rigidBodyInfo.m_centerOfMass = m_massProperties.m_centerOfMass;
	m_rigidBodyInfo.m_inertiaTensor = m_massProperties.m_inertiaTensor;
	m_rigidBodyInfo.m_shape = movingBodyShape;
	
	// If sphere is movable or not
	if(movable) {
		m_rigidBodyInfo.m_motionType = hkpMotion::MOTION_BOX_INERTIA;
	} else {
		m_rigidBodyInfo.m_motionType = hkpMotion::MOTION_FIXED;
	}
	
	// Create new rigid body with supplied info
	m_rigidBody = new hkpRigidBody(m_rigidBodyInfo);
	movingBodyShape->removeReference();
}